package com.kgc.scd.controller;

import com.kgc.scd.annotation.RequestPermission;
import com.kgc.scd.annotation.RequestUser;
import com.kgc.scd.service.BuyVipService;
import com.kgc.scd.util.RequestResult;
import com.kgc.scd.util.ResultBuildUtil;
import com.kgc.scd.util.UserAnno;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Created On : 2022/6/18.
 * <p>
 * Author     : 15950526365
 * <p>
 * Description: 买会员的操作入口
 */
@RestController
@Api(tags = "12、买会员操作入口")
public class BuyVipController {

    @Autowired(required = false)
    private BuyVipService buyVipService;

    @PostMapping("/placeVipOrder")
    @ApiOperation(value = "生成vip订单号")
    @RequestPermission
    public RequestResult<Map<String, Object>> placeVipOrder(@RequestUser UserAnno userAnno){
        Map<String, Object> results = buyVipService.placeVipOrder(userAnno.getUserId());
        return ResultBuildUtil.success(results);
    }


    @PostMapping("/payVip")
    @ApiOperation(value = "支付vip购买订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单编号")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "SUCCESS"),
            @ApiResponse(code = 500, message = "FAIL")
    })
    public RequestResult<Map<String, String>> payVip(@RequestUser UserAnno userAnno,
                         @RequestParam(value = "orderId")String orderId){
        RequestResult<Map<String, String>> mapRequestResult = buyVipService.wechatPayUnifiedOrder(orderId, userAnno.getUserId());
        return mapRequestResult;
    }


}
